<!DOCTYPE html>
<!-- 网页使用的语言 -->
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>图书管理系统</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="/static/js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="/static/js/bootstrap.min.js"></script>
    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>
</head>


<body>
<div class="container">

    <ul class="nav nav-pills">
      <li role="presentation"><a href="{% url 'presslist' %}">出版社列表</a></li>
      <li role="presentation" class="active"><a href="/booklist/">图书列表</a></li>
      <li role="presentation"><a href="/booktypelist/">图书类型</a></li>
    </ul>

    <h3 style="text-align: center">图书信息列表</h3>
    <form action="/booksearch/" method="post">
        <div class="form-group">
            <input style="width: 300px;display: inline" type="text" class="form-control" id="bookname" name="bookname" value="{{ bookname }}"  placeholder="请输入图书名称" />
            <button type="submit" class="btn btn-warning glyphicon glyphicon-search">搜索</button>
        </div>
    </form>


    <table border="1" class="table table-bordered table-hover">
        <tr class="success">
            <th>编号</th>
            <th>图书名称</th>
            <th>图书价格</th>
            <th>图书作者</th>
            <th>图书图片</th>
            <th>图书出版社</th>
            <th>操作</th>
        </tr>

        {% for book in booklist %}
            <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ book.bookname|default:"ddd" }}</td>
                <td>{{ book.bookprice }}</td>
                <td>{{ book.bookauthor }}</td>
                <td> <img src="{{ book.bookimg }}" width="100px" height="100px"> </td>
                <td>{{ book.press.pressname }}</td>
                <td>
                    <a class="btn btn-info btn-sm glyphicon glyphicon-pencil" href="/bookupdate?id={{ book.id }}">修改</a>&nbsp;
                    {% comment %}<a class="btn btn-danger btn-sm glyphicon glyphicon-trash" href="/bookdelete?id={{ book.id }}" onclick="return confirm('您确定删除吗？')">删除</a>{% endcomment %}
                    <a class="btn btn-danger glyphicon glyphicon-trash btn-sm"  data-id="{{ book.id }}" data-toggle="modal" data-target="#myModal">删除</a>
                </td>
            </tr>
        {% endfor %}




        <tr>
            <td colspan="8" align="center"><a class="btn btn-primary glyphicon glyphicon-plus" href="/bookadd/">添加图书</a></td>
        </tr>
    </table>
    <div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="myModalLabel">信思智学提醒您</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            删除后不可恢复，确定删除吗？
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary" id="sub">确定</button>
          </div>
        </div>
      </div>
    </div>


</div>
<script>
    $(function () {
        $('#myModal').on('show.bs.modal', function (event) {
            // 获取触发模态框的按钮
            var button = $(event.relatedTarget); // Button that triggered the modal
            // 获取 data-id 属性值
            var dataId = button.data('id'); // Extract info from data-* attributes
            // 你可以在这里使用 dataId
            $("#sub").click(function () {
                window.location.href = "/bookdelete/?id="+dataId
            });
        });
    })
</script>
</body>
</html>
